<?php

class JKConfigBean {
	
	 public static function get_all_config_data($db,$langid) {
        $strSQL = sprintf("SELECT * FROM ".TBL_CONFIG_MANAGER." c WHERE c.lang_id = '$langid'");
		$res =  $db->get_row($strSQL);
		if($res!=""){
			$res->site_title = html_entity_decode($res->site_title);
			$res->keywords = html_entity_decode($res->keywords);
			$res->description = html_entity_decode($res->description);
			$res->copyright = html_entity_decode($res->copyright);
		}
        return $res;
	}
	
	public static function update_config_data($db,$config, $lang_id) {
    	$sql = sprintf("UPDATE %s SET " .
    			"site_title = '%s', " .
				"keywords = '%s', " .
				"description = '%s', " .
				"copyright = '%s' " .
    			"WHERE lang_id = '". $lang_id ."'", 
				TBL_CONFIG_MANAGER,
    			htmlentities($config['site_title'], ENT_QUOTES),
				htmlentities($config['keywords'], ENT_QUOTES),
				htmlentities($config['description'], ENT_QUOTES),
				htmlentities($config['copyright'], ENT_QUOTES));
    	$res = $db->query($sql) >= 0;

    	return $res;
	}
	
	public static  function save_config_data($db, $config,$lang_id){
    	$res = $db->query(sprintf(
					"INSERT INTO %s(site_title , keywords, description,copyright,lang_id) " .
					"VALUES('%s', '%s', '%s', '%s', '%s')",
    				TBL_CONFIG_MANAGER, 
    				htmlentities($config['site_title'], ENT_QUOTES),
    				htmlentities($config['keywords'], ENT_QUOTES),
					htmlentities($config['description'], ENT_QUOTES),
    				htmlentities($config['copyright'], ENT_QUOTES),
    				$lang_id));
    				
    	if($res == true)
    		return $db->insert_id;
    	else
    		return -1;
    }
}
?>